package com.animee.day11.slice;

import com.animee.day11.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    Button btn1,btn2,btn3,btn4,btn5;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
    }

    private void initView() {
        btn1 = findComponentById(ResourceTable.Id_main_btn1);
        btn2 = findComponentById(ResourceTable.Id_main_btn2);
        btn3 = findComponentById(ResourceTable.Id_main_btn3);
        btn4 = findComponentById(ResourceTable.Id_main_btn4);
        btn5 = findComponentById(ResourceTable.Id_main_btn5);
        //设置点击事件
        MyClickListener listener = new MyClickListener();
        btn1.setClickedListener(listener);
        btn2.setClickedListener(listener);
        btn3.setClickedListener(listener);
        btn4.setClickedListener(listener);
        btn5.setClickedListener(listener);
    }
    class MyClickListener implements Component.ClickedListener{
        @Override
        public void onClick(Component component) {
            Intent intent = new Intent();
            switch (component.getId()) {
                case ResourceTable.Id_main_btn1:
                    //跳转到猜数游戏页面
                    present(new GuessNumAbilitySlice(),intent);
                    break;
                case ResourceTable.Id_main_btn2:
                    present(new FingerAbilitySlice(),intent);
                    break;
                case ResourceTable.Id_main_btn3:
                    present(new BMIAbilitySlice(),intent);
                    break;
                case ResourceTable.Id_main_btn4:
                    present(new FilmTypeAbilitySlice(),intent);
                    break;
                case ResourceTable.Id_main_btn5:
                    present(new PageSliderAbilitySlice(),intent);
                    break;
            }
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
